﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace mapxp
{
    class Map
    {
        private string _filename;
        private double[,] _twoDimArray;
        private int _size_y; // the size of the matrix
        private int _size_x; // the size of the matrix
        private double _max_z;
        private int _y_starts;
        private int _x_starts;
        private int _x0;    //the diff between each double in the file
        private int _y0;    //the diff between each double in the file



        //constractor get's only file location
        public Map(string name)
        {
            StreamReader re = File.OpenText(name);
            string temp1, temp2 = null;
            int i = 0;
            temp1 = re.ReadLine();
            while (!temp1.Substring(i, 1).Equals(" "))
            {
                _filename = _filename + temp1.Substring(i, 1);
                i++;
            }
            i++;
            while (!temp1.Substring(i, 1).Equals(" "))
            {
                temp2 = temp2 + temp1.Substring(i, 1);
                i++;
            }
            i++;
            _size_x = Convert.ToInt32(temp2, 10);
            temp2 = null;
            while (!temp1.Substring(i, 1).Equals(" "))
            {
                temp2 = temp2 + temp1.Substring(i, 1);
                i++;
            }
            i++;
            _size_y = Convert.ToInt32(temp2, 10);
            temp2 = null;
            while (!temp1.Substring(i, 1).Equals(" "))
            {
                temp2 = temp2 + temp1.Substring(i, 1);
                i++;
            }
            i++;
            _max_z = Convert.ToDouble(temp2);
            temp2 = null;
            while (!temp1.Substring(i, 1).Equals(" "))
            {
                temp2 = temp2 + temp1.Substring(i, 1);
                i++;
            }
            i++;
            _x_starts = Convert.ToInt32(temp2, 10);
            temp2 = null;
            while (!temp1.Substring(i, 1).Equals(" "))
            {
                temp2 = temp2 + temp1.Substring(i, 1);
                i++;
            }
            i++;
            _y_starts = Convert.ToInt32(temp2, 10);
            temp2 = null;
            while (!temp1.Substring(i, 1).Equals(" "))
            {
                temp2 = temp2 + temp1.Substring(i, 1);
                i++;
            }
            i++;
            _x0 = Convert.ToInt32(temp2, 10);
            temp2 = temp1.Substring(i, temp1.Length - i);
            _y0 = Convert.ToInt32(temp2, 10);
            _twoDimArray = new double[_size_x, _size_y];
            temp2 = null;
            temp1 = re.ReadToEnd();
            int k = 0, j = _size_y - 1;
            for (i = 0; i < temp1.Length; i++)
            {
                if (temp1.Substring(i, 1).Equals(" "))
                {
                    _twoDimArray[k, j] = Convert.ToDouble(temp2);
                    k++;
                    if (k == _size_x)
                    {
                        k = 0;
                        j--;
                    }
                    temp2 = null;
                }
                else
                {
                    temp2 = temp2 + temp1.Substring(i, 1);
                }
            }
            re.Close();

        }


        public Map(double[,] a)
        {
            _filename = null;
            _twoDimArray = a;
            _size_y = 0;
            _size_x = 0;
            _max_z = 0;
            _y_starts = 0;
            _x_starts = 0;
            _x0 = 0;
            _y0 = 0;


        }

        public Map()
        {
            _filename = null;
            _twoDimArray = new double[100, 100];
            _size_y = 0;
            _size_x = 0;
            _max_z = 0;
            _y_starts = 0;
            _x_starts = 0;
            _x0 = 0;
            _y0 = 0;


        }
        //seters methods
        public void setXSize(int size)
        {
            _size_x = size;
        }
        public void setYSize(int size)
        {
            _size_y = size;
        }
        public void setMaxZValue(double zValue)
        {
            _max_z = zValue;
        }
        public double getMaxZValue()
        {
            return _max_z;
        }
        // usually 0
        public void setXStartsFrom(int xStartsValue)
        {
            _x_starts = xStartsValue;
        }
        // usually 0   
        public void setYStartsFrom(int yStartsValue)
        {
            _y_starts = yStartsValue;
        }
        // the diff between every x line
        public void setX0(int x0)
        {
            _x0 = x0;
        }
        // the diff between every y line
        public void setY0(int y0)
        {
            _y0 = y0;
        }
        public double[,] getArray()
        {
            return _twoDimArray;
        }
        public void setArray(double[,] a)
        {
            _twoDimArray = a;
        }
        public int getXSizeOfArray()
        {
            return _size_x;
        }
        public int getYSizeOfArray()
        {
            return _size_y;
        }
        //double getZMaxValue(): // not needded in this ex
        public double getX0()
        {
            return _x0;
        }
        public double getY0()
        {
            return _y0;
        }
        public double getxStartingPoint()
        {
            return _x_starts;
        }
        public double getYStartingPoint()
        {
            return _y_starts;
        }
        public void setName(string name)
        {
            _filename = name;
        }
        public string getName()
        {
            return _filename;
        }




    }
}
